package org.raymond.iworks.study.basic.designpattern.factory.simple.pizzastore.order;

import org.raymond.iworks.study.basic.designpattern.factory.simple.pizzastore.pizza.Pizza;

import java.util.Scanner;

/**
 * @author raymond
 * @version V1.0
 * @Description: TODO
 */
public class OrderPizza {
    private SimpleFactory simpleFactory;
    public OrderPizza(SimpleFactory simpleFactory){
        setFactory(simpleFactory);
    }

    public void setFactory(SimpleFactory simpleFactory){
        this.simpleFactory = simpleFactory;
        while(true){
            Pizza pizza = simpleFactory.createPizza(getType());
            if(pizza != null){
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else{
                System.out.println("订购披萨失败");
                break;
            }
        }
    }

    private String getType(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入披萨的种类:");
        String str = scanner.next();
        return str;
    }
}
